let api = [];
api.push({
    alias: 'debug',
    order: '1',
    desc: '权限管理',
    link: '权限管理',
    list: []
})
api[0].list.push({
    order: '1',
    desc: '分页获取用户列表',
});
api[0].list.push({
    order: '2',
    desc: '设置用户状态',
});
api[0].list.push({
    order: '3',
    desc: '删除用户（只能单个删除）',
});
api[0].list.push({
    order: '4',
    desc: '根据id获取用户资料',
});
api[0].list.push({
    order: '5',
    desc: '新增用户',
});
api[0].list.push({
    order: '6',
    desc: '修改用户数据',
});
api[0].list.push({
    order: '7',
    desc: '修改用户密码',
});
api[0].list.push({
    order: '8',
    desc: '获取角色列表',
});
api[0].list.push({
    order: '9',
    desc: '根据id获取角色信息',
});
api[0].list.push({
    order: '10',
    desc: '新增角色',
});
api[0].list.push({
    order: '11',
    desc: '修改角色信息',
});
api[0].list.push({
    order: '12',
    desc: '删除角色',
});
api[0].list.push({
    order: '13',
    desc: '获取用户角色权限关系',
});
api[0].list.push({
    order: '14',
    desc: '用户角色授权',
});
api[0].list.push({
    order: '15',
    desc: '获取角色拥有的权限区域',
});
api[0].list.push({
    order: '16',
    desc: '角色区域授权',
});
api[0].list.push({
    order: '17',
    desc: '获取角色拥有的模块菜单权限',
});
api[0].list.push({
    order: '18',
    desc: '授权角色模块菜单',
});
api[0].list.push({
    order: '19',
    desc: '获取所有模块功能菜单',
});
api[0].list.push({
    order: '20',
    desc: '根据id获取模块信息',
});
api[0].list.push({
    order: '21',
    desc: '新增模块',
});
api[0].list.push({
    order: '22',
    desc: '修改模块信息',
});
api[0].list.push({
    order: '23',
    desc: '修改模块排序',
});
api[0].list.push({
    order: '24',
    desc: '删除模块',
});
api[0].list.push({
    order: '25',
    desc: '根据id获取菜单功能数据',
});
api[0].list.push({
    order: '26',
    desc: '新增菜单功能',
});
api[0].list.push({
    order: '27',
    desc: '修改菜单功能数据',
});
api[0].list.push({
    order: '28',
    desc: '修改菜单功能数据',
});
api[0].list.push({
    order: '29',
    desc: '删除菜单功能',
});
api[0].list.push({
    order: '30',
    desc: '获取完整权限列表',
});
api[0].list.push({
    order: '31',
    desc: '获取菜单功能已绑定的资源权限',
});
api[0].list.push({
    order: '32',
    desc: '设置菜单功能资源权限',
});
api[0].list.push({
    order: '33',
    desc: '分页获取系统配置列表',
});
api[0].list.push({
    order: '34',
    desc: '根据id获取系统配置参数数据',
});
api[0].list.push({
    order: '35',
    desc: '删除系统配置',
});
api[0].list.push({
    order: '36',
    desc: '新增系统配置',
});
api[0].list.push({
    order: '37',
    desc: '修改系统配置（详细）',
});
api[0].list.push({
    order: '38',
    desc: '获取系统配置分组',
});
api[0].list.push({
    order: '39',
    desc: '根据分组查询系统配置列表',
});
api[0].list.push({
    order: '40',
    desc: '修改配置值',
});
api.push({
    alias: '32ba5dac3ed1d9e3912634a7b2f79169',
    order: '2',
    desc: '基础数据',
    link: '基础数据',
    list: []
})
api[1].list.push({
    order: '1',
    desc: '获取所有区域信息',
});
api[1].list.push({
    order: '2',
    desc: '根据id获取区域信息',
});
api[1].list.push({
    order: '3',
    desc: '新增区域',
});
api[1].list.push({
    order: '4',
    desc: '修改区域信息',
});
api[1].list.push({
    order: '5',
    desc: '删除区域',
});
api[1].list.push({
    order: '6',
    desc: '获取区域设备',
});
api[1].list.push({
    order: '7',
    desc: '新增区域设备关联',
});
api[1].list.push({
    order: '8',
    desc: '删除区域设备',
});
api[1].list.push({
    order: '9',
    desc: '获取区域设备列表',
});
api[1].list.push({
    order: '10',
    desc: '查询区域设备计量点信息',
});
api[1].list.push({
    order: '11',
    desc: '删除区域设备计量点关系',
});
api[1].list.push({
    order: '12',
    desc: '新增区域设备计量点关系',
});
api[1].list.push({
    order: '13',
    desc: '修改区域设备计量点关系',
});
api[1].list.push({
    order: '14',
    desc: '根据id获取设备信息',
});
api[1].list.push({
    order: '15',
    desc: '分页获取设备列表',
});
api[1].list.push({
    order: '16',
    desc: '删除设备',
});
api[1].list.push({
    order: '17',
    desc: '新增设备',
});
api[1].list.push({
    order: '18',
    desc: '修改设备信息',
});
api[1].list.push({
    order: '19',
    desc: '根据id获取设备类型数据',
});
api[1].list.push({
    order: '20',
    desc: '获取所有设备类型列表',
});
api[1].list.push({
    order: '21',
    desc: '删除设备类型',
});
api[1].list.push({
    order: '22',
    desc: '新增设备类型',
});
api[1].list.push({
    order: '23',
    desc: '修改设备类型数据',
});
api[1].list.push({
    order: '24',
    desc: '根据id获取计量点数据',
});
api[1].list.push({
    order: '25',
    desc: '分页获取计量点列表',
});
api[1].list.push({
    order: '26',
    desc: '删除计量点',
});
api[1].list.push({
    order: '27',
    desc: '设置计量点市平台上传标记',
});
api[1].list.push({
    order: '28',
    desc: '设置计量点预警标记',
});
api[1].list.push({
    order: '29',
    desc: '新增计量点',
});
api[1].list.push({
    order: '30',
    desc: '修改计量点信息',
});
api[1].list.push({
    order: '31',
    desc: '获取所以表具列表',
});
api[1].list.push({
    order: '32',
    desc: '分页获取表具列表',
});
api[1].list.push({
    order: '33',
    desc: '根据id获取表具数据',
});
api[1].list.push({
    order: '34',
    desc: '删除表具',
});
api[1].list.push({
    order: '35',
    desc: '新增表具',
});
api[1].list.push({
    order: '36',
    desc: '修改表具信息',
});
api[1].list.push({
    order: '37',
    desc: '获取表参列表',
});
api[1].list.push({
    order: '38',
    desc: '根据id获取表参数据',
});
api[1].list.push({
    order: '39',
    desc: '删除表参数据',
});
api[1].list.push({
    order: '40',
    desc: '新增表参数据',
});
api[1].list.push({
    order: '41',
    desc: '修改表参数据',
});
api[1].list.push({
    order: '42',
    desc: '根据id获取能源数据',
});
api[1].list.push({
    order: '43',
    desc: '获取所有能源列表',
});
api[1].list.push({
    order: '44',
    desc: '删除能源',
});
api[1].list.push({
    order: '45',
    desc: '新增能源',
});
api[1].list.push({
    order: '46',
    desc: '修改能源数据',
});
api[1].list.push({
    order: '47',
    desc: '根据id获取能源价格',
});
api[1].list.push({
    order: '48',
    desc: '获取能源价格数据',
});
api[1].list.push({
    order: '49',
    desc: '删除能源价格',
});
api[1].list.push({
    order: '50',
    desc: '新增能源价格',
});
api[1].list.push({
    order: '51',
    desc: '修改能源价格',
});
api.push({
    alias: '7111afde44bf5d792a5bad72fa6ab6f3',
    order: '3',
    desc: '通用接口',
    link: '通用接口',
    list: []
})
api[2].list.push({
    order: '1',
    desc: '获取用户的权限区域列表（简略）',
});
api[2].list.push({
    order: '2',
    desc: '获取所有能源列表',
});
api[2].list.push({
    order: '3',
    desc: '获取设备列表',
});
api[2].list.push({
    order: '4',
    desc: '获取计量点列表',
});
api.push({
    alias: '70cf620ea4db4822b6fa7cd42d866185',
    order: '4',
    desc: '文件管理',
    link: '文件管理',
    list: []
})
api[3].list.push({
    order: '1',
    desc: '文件上传',
});
api[3].list.push({
    order: '2',
    desc: '文件空间',
});
api[3].list.push({
    order: '3',
    desc: '文件删除',
});
api.push({
    alias: '5ef0372631ec988ca4fdb9137553c7cc',
    order: '5',
    desc: '开放接口',
    link: '开放接口',
    list: []
})
api[4].list.push({
    order: '1',
    desc: '获取系统标题',
});
api[4].list.push({
    order: '2',
    desc: '获取配置',
});
api.push({
    alias: '5b46cd366e910ec668ca3bd765dfeab4',
    order: '6',
    desc: '用户中心',
    link: '用户中心',
    list: []
})
api[5].list.push({
    order: '1',
    desc: '登录',
});
api[5].list.push({
    order: '2',
    desc: '获取登录用户信息',
});
api[5].list.push({
    order: '3',
    desc: '修改密码',
});
api[5].list.push({
    order: '4',
    desc: '获取用户的权限模块',
});
api[5].list.push({
    order: '5',
    desc: '获取用户的权限功能',
});
api[5].list.push({
    order: '6',
    desc: '登出',
});
api.push({
    alias: 'error',
    order: '7',
    desc: '错误码列表',
    link: 'error_code_list',
    list: []
})
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code === 13) {
        const search = document.getElementById('search');
        const searchValue = search.value;
        let searchArr = [];
        for (let i = 0; i < api.length; i++) {
            let apiData = api[i];
            const desc = apiData.desc;
            if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchArr.push({
                    order: apiData.order,
                    desc: apiData.desc,
                    link: apiData.link,
                    alias: apiData.alias,
                    list: apiData.list
                });
            } else {
                let methodList = apiData.list || [];
                let methodListTemp = [];
                for (let j = 0; j < methodList.length; j++) {
                    const methodData = methodList[j];
                    const methodDesc = methodData.desc;
                    if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                        methodListTemp.push(methodData);
                        break;
                    }
                }
                if (methodListTemp.length > 0) {
                    const data = {
                        order: apiData.order,
                        desc: apiData.desc,
                        alias: apiData.alias,
                        link: apiData.link,
                        list: methodListTemp
                    };
                    searchArr.push(data);
                }
            }
        }
        let html;
        if (searchValue === '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchArr,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            let $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiData, liClass, display) {
    let html = "";
    if (apiData.length > 0) {
         for (let j = 0; j < apiData.length; j++) {
            html += '<li class="'+liClass+'">';
            html += '<a class="dd" href="' + apiData[j].alias + '.html#header">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
            html += '<ul class="sectlevel2" style="'+display+'">';
            let doc = apiData[j].list;
            for (let m = 0; m < doc.length; m++) {
                html += '<li><a href="' + apiData[j].alias + '.html#_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + doc[m].desc + '</a> </li>';
            }
            html += '</ul>';
            html += '</li>';
        }
    }
    return html;
}